package com.gel.aiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgDistanceType.COSINE_DISTANCE;
import static org.springframework.ai.vectorstore.pgvector.PgVectorStore.PgIndexType.HNSW;

@Configuration
public class PgVectorVectorStoreConfig {

    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Bean
    public VectorStore pgVevctorVectorStore(@Qualifier("postgresJdbcTemplate")JdbcTemplate jdbcTemplate, EmbeddingModel dashscopeEmbeddingModel, VectorStore loveAppVectorStore){
        VectorStore vectorStore= PgVectorStore.builder(jdbcTemplate, dashscopeEmbeddingModel)
                .dimensions(1536)
                .schemaName("public")
                .distanceType(COSINE_DISTANCE)
                .vectorTableName("vector_store")
                .indexType(HNSW)
                .initializeSchema(true)
                .maxDocumentBatchSize(10000)
                .build();
//        List<Document> documents = loveAppDocumentLoader.laodMarkdowns();
//        vectorStore.add( documents);
        return vectorStore;
    }
}
